package com.zh.note.huawei.onehundred.最小施肥机能效;

import java.util.Arrays;

/**
 * @Author: zhanghuan
 * @date: 2023/8/3 22:23
 * @description: create it
 */
public class Main {
    /**
     * 怎么计算果林施肥完成天数？
     *
     * @param args
     */
    public static void main(String[] args) {
        // Scanner sc = new Scanner(System.in);
        // int len = sc.nextInt();
        // int day = sc.nextInt();
        // int[] fields = new int[len];
        // for (int i = 0; i < len; i++) {
        //     fields[i] = sc.nextInt();
        // }
        int len = 5;
        int day = 7;
        int[] fields = {5, 7, 9, 15, 10};
        int left = 1;
        int right = Arrays.stream(fields).max().orElse(0); // right取最大值
        while (left < right) {
            int mid = (left + right) / 2;
            int groups = 0; //统计需要多少天
            for (int i = 0; i < fields.length; i++) {
                if (fields[i] % mid == 0) {
                    groups += fields[i] / mid;
                } else {
                    groups += fields[i] / mid + 1;
                }
            }
            if (groups <= day) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        int groups = 0;
        for (int i = 0; i < fields.length; i++) {
            if (fields[i] % left == 0) {
                groups += fields[i] / left;
            } else {
                groups += fields[i] / left + 1;
            }
        }
        System.out.println(groups > day ? -1 : left);

    }
}
